
var express = require('express')

var bodyParser = require('body-parser')


var app = express()

var index = require('./routes/index')
var admin = require('./routes/admin')

var session = require('express-session')
//配置session
app.use(session({
    secret: '12345', 
    name: 'mySession',
    resave: false,
    saveUninitialized: true,
    cookie: {
        maxAge: 60*1000*60
    },
    rolling: true
}))

//ejs中设置全局数据,所有的ejs页面都可以使用
// app.locals['userInfo'] = "22222"

//配置静态目录
app.use(express.static('static'))
app.use('/upload',express.static('upload'))

//配置body-parser中间件
//parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({
    extended: false
}))
//parse application/json
app.use(bodyParser.json())

//设置ejs模板引擎---默认找views目录
app.set('view engine','ejs')

//设置路由
app.use('/admin',admin)
app.use('/',index)

app.use(function (req, res) {
    res.status(404)
    res.send('404--没有路由匹配')
})

app.listen(3000, '127.0.0.1')